﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;
using System.Dynamic;
using FluorineFx.Json;

namespace lxwmvc
{
   
    public static class example2controller
    {
        /// <summary>
        /// 全局引用
        /// </summary>
        /// <param name="pb"></param>
        public static void _init(pagebase pb)
        {
            
        }

        [json]
        public static void model(pagebase pb)
        {
            BaseJson json = pb.JSON<BaseJson>();
            //用实体存在一个问题，就是属性是否变化，定义的时候也需要考虑，最好用?,但是操作起来就比较麻烦
            yonghu yonghu = pb.model().toModel<yonghu>();
            supermodel sm1 = pb.model().fromModel(yonghu);

            yonghu y = new lxwmvc.yonghu();
            y = (y + pb.model()) as yonghu;

            json.data = sm1.ToString();
        }

        [json]
        public static void geta(pagebase pb)
        {
            BaseJson json = pb.JSON<BaseJson>();
            supermodel sm = pb.model("yonghu");

            json.data = sm.ToString();
        }

        [json]
        public static void posta(pagebase pb)
        {
            BaseJson json = pb.JSON<BaseJson>();
            supermodel sm = pb.model("yonghu");

            json.data = sm.ToString();
        }

        [json]
        public static void log(pagebase pb)
        {
            //info
            dataloger.info("info");

            //error
            dataloger.error("error",new Exception("error 。。。。"));

            //fatal
            dataloger.fatal("fatal", new Exception("fatal 。。。。"));

            //warn
            dataloger.warn("warn");

            //debug
            dataloger.debug("debug");
        }


        [json]
        [trans]
        //[trans(IsolationLevel.RepeatableRead)] 下面控制事务的级别
        public static void testtrans(pagebase pb)
        {
            BaseJson json = pb.JSON<BaseJson>();
            dynamic yonghu = supermodel.create("yonghu");
            yonghu.xingming = "测试1";
            //描述
            yonghu.miaoshu = "描述！！！";
            yonghu.saveorupdate();

            yonghu = supermodel.create("yonghu");
            yonghu.xingming = "测试2";
            //描述
            yonghu.miaoshu = "描述！！！222";
            yonghu.saveorupdate();

            json.data = yonghu.ToString();

            throw new Exception("错误1");
        }

        [json]
        //[trans] 不带事务
        public static void testnotrans(pagebase pb)
        {
            BaseJson json = pb.JSON<BaseJson>();
            dynamic yonghu = supermodel.create("yonghu");
            yonghu.xingming = "测试3";
            //描述
            yonghu.miaoshu = "描述！！！";
            yonghu.saveorupdate();

            yonghu = supermodel.create("yonghu");
            yonghu.xingming = "测试4";
            //描述
            yonghu.miaoshu = "描述！！！222";
            yonghu.saveorupdate();

            json.data = yonghu.ToString();

            throw new Exception("错误2");
        }

        [json]
        public static void testpager(pagebase pb)
        {
            BaseJson json = pb.JSON<BaseJson>();

            dynamic pageing = pb.bodyjson().tosm();

            var pi = queryhelper.pager("yonghu", "*", "yonghuid", pageing.pageNo, pageing.pageSize);

            pi = queryhelper.pager("select * from yonghu", pageing.pageNo, pageing.pageSize);
            //把分页信息输出为json信息
            json.data = pi.tojson();
        }

        [json]
        public static void test11(pagebase pb)
        {
            dynamic model = supermodel.create("ddd");
            var supmodel1 = (supermodel)model;

            var supmodel2 = model as supermodel;

            //对象复制
            var newmodel = supmodel2.clone();
        }
    }
}